package com.example.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.bean.CmsComment;
import com.example.demo.common.Response;
import com.example.demo.service.CmsCommentService;

@RestController
@RequestMapping("/comment")
public class CmsCommentController {
	
	@Autowired
	private CmsCommentService cmsCommentService;
	@GetMapping("/selectAll")
	public Response<List<CmsComment>> selectAll() {
		List<CmsComment> list = cmsCommentService.selectAll();
		return Response.ok(list);
	}
	
	@DeleteMapping("/deleteById")
	public Response<String> deleteById(String id)
	{
		int count = cmsCommentService.deleteById(id);
		if (count == -1) {
			return Response.error("删除失败！！！");
		}
		return Response.ok("成功删除了："+count+"个会员！！！");
	}
	
	@DeleteMapping("/deleteByIds")
	public Response<String> deleteByIds(String[] ids)
	{
		int count = cmsCommentService.batchDeleteByIds(ids);
		if (count ==0) {
			return Response.error("删除失败！！！");
		}
		return Response.ok("成功删除"+count+"条链接信息！！！");
	}
	
	@PostMapping("/saveOrUpdate")
	public Response<String> saveOrUpdate(CmsComment cmsComment) {
		
		int count = cmsCommentService.saveOrUpdate(cmsComment);
		if (count==-2) {
			return Response.error("父栏目不存在！！！");
		}else if (count ==-1) {
			return Response.error("更新ID不存在！！！");
		}
		return Response.ok("保存或更新成功！！！");
	}
}

